/** The status display mode.
 *@param buffer The buffer to render to.
 *@param x The x offset.
 *@param y The y offset.
 *@param width The width.
 *@param height The height.
 */
function StatusMode(buffer, x, y, width, height)
{
	this.buffer = buffer;
	this.x = x;
	this.y = y;
	this.width = width;
	this.height = height;
}
StatusMode.prototype =
{
	lastHp: null,
	lastHpMax: null,
	lastSp: null,
	lastSpMax: null,
	lastXp: null,
	lastWeight: null,
	lastWeightMax: null,
	/** Re-render the entire display.
	 */
	render: function(isUpdate)
	{
		var yOfs = 0;
		if(!isUpdate)
		{
			// Left border and player name
			this.buffer.blitRect(this.x, this.y, 1, this.height, " ", null, Color.black);
			if(this.height > yOfs)
				this.buffer.blitStringCentered(this.x + 1, this.y + yOfs, "%f0" + dhack.player.name, this.width - 1);
		}
		++yOfs;
		// HP display
		if(!isUpdate ||
			this.lastHp != dhack.player.hp ||
			this.lastHpMax != dhack.player.hpMax)
		{
			this.lastHp = dhack.player.hp;
			this.lastHpMax = dhack.player.hpMax;
			if(this.height > yOfs)
			{
				this.buffer.blitStringCentered(this.x + 1, this.y + yOfs, "%f0Health " + util.floatDigits(dhack.player.hp, 0) + "%%", this.width - 1);
				this.buffer.blitProgressBar(this.x + 1, this.y + yOfs, this.width - 1, dhack.player.hp / dhack.player.hpMax, Color.red, Color.darkRed, Color.darkGray);
			}
		}
		++yOfs;
		// SP display
		if(!isUpdate ||
			this.lastSp != dhack.player.sp ||
			this.lastSpMax != dhack.player.spMax)
		{
			this.lastSp = dhack.player.sp;
			this.lastSpMax = dhack.player.spMax;
			if(this.height > yOfs)
			{
				this.buffer.blitStringCentered(this.x + 1, this.y + yOfs, "%f0Stamina " + util.floatDigits(dhack.player.sp, 0) + "%%", this.width - 1);
				this.buffer.blitProgressBar(this.x + 1, this.y + yOfs, this.width - 1, dhack.player.sp / dhack.player.spMax, Color.darkGreen, Color.teal, Color.darkGray);
			}
		}
		++yOfs;
		// Experiance display
		if(!isUpdate ||
			this.lastXp != dhack.player.xp)
		{
			this.lastXp = dhack.player.xp;
			if(this.height > yOfs)
			{
				this.buffer.blitStringCentered(this.x + 1, this.y + yOfs, "%f0LV " + dhack.player.level + " XP " + dhack.player.exp, this.width - 1);
				this.buffer.blitProgressBar(this.x + 1, this.y + yOfs, this.width - 1, dhack.player.exp / 100, Color.magenta, Color.purple, Color.darkGray);
			}
		}
		++yOfs;
		// Weight display
		if(!isUpdate ||
			this.lastWeight != dhack.player.weight ||
			this.lastWeightMax != dhack.player.weightMax)
		{
			this.lastWeight = dhack.player.weight;
			this.lastWeightMax = dhack.player.weightMax;
			if(this.height > yOfs)
			{
				this.buffer.blitStringCentered(this.x + 1, this.y + yOfs, "%f0WT " + util.floatDigits(dhack.player.weight, 1) + "(" + util.floatDigits(dhack.player.weightMax, 1) + ")", this.width - 1);
				this.buffer.blitProgressBar(this.x + 1, this.y + yOfs, this.width - 1, dhack.player.weight / dhack.player.weightMax, Color.brown, Color.darkRed, Color.darkGray);
			}
		}
		++yOfs;

		// Render status effects
		this.buffer.blitStringCentered(this.x + 1, this.y + yOfs, "%f0Status Effects", this.width - 1);
		++yOfs;
		for(var i = 0; i < dhack.player.effects.length; ++i)
		{
			var effect = dhack.player.effects[i];
			this.buffer.blitStringCentered(this.x + 1, this.y + yOfs, "%f0" + effect.name, this.width - 1);
			this.buffer.blitProgressBar(this.x + 1, this.y + yOfs, this.width - 1, effect.duration / effect.durationMax, Color.blue, Color.darkBlue, Color.darkGray);
			++yOfs;
		}
		
		// TODO Render legend information
		
		// Blank the rest of the area
		// TODO Record how far down we rendered last update and only blank down to that point if needed.
		this.buffer.blitRect(this.x + 1, this.y + yOfs, this.width - 1, this.height - yOfs, " ", null, Color.black);
	}
};
